package main

import (
	"context"
	"fmt"
	"gitee.com/alex_li/rodinbell/application"
	"gitee.com/alex_li/rodinbell/etc"
	"github.com/lishimeng/app-starter"
	"github.com/lishimeng/go-log"
	"time"
)

func main() {

	var err error

	configName := "config.toml"
	log.SetLevelAll(log.INFO)

	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
		}
	}()

	appInstance := app.New()


	err = appInstance.
		Start(func(ctx context.Context, builder *app.ApplicationBuilder) error {
			err := builder.LoadConfig(&etc.Config, configName, ".")
			if err != nil {
				return err
			}

			go func() {
				application.InitCache(1 * time.Second, 30 * time.Second)

				for {
					application.Run(ctx)
					time.Sleep(time.Second * 2)
				}
			}()

			return nil
	}, func(s string) {
	})

	if err != nil {
		log.Info(err)
	}

	time.Sleep(time.Second * 2)
}
